import { ref } from 'vue';
import { getInboundOrdersDetailsApi } from '@/api/sj/purchaseManagement/toBeStored/index'

const useViewNotes = () => {

    const viewNotesVisible = ref(false);
    const detailVisible = ref(false);
    const viewNotesObj = ref({});
    const detailObj = ref();
    const detailRow = ref({});

    /**
     * @description: 查看备注
     */
    const handleViewNotes = (row: any) => {
        console.log(row);
        viewNotesObj.value = row
        viewNotesVisible.value = true;
    };

    /**
     * @description: 查看详情
     */
    const handleOpenDetail = async (row: any) => {
        const data = await handleGetPurchaseDetails(row)
        detailObj.value = data
        detailRow.value = row
        detailVisible.value = true;
    };


    /**
     * 获取采购入库详情
     */
    const handleGetPurchaseDetails = (row: any) => {
        return new Promise((resolve, reject) => {
            getInboundOrdersDetailsApi(row.id).then((res: any) => {
                resolve(res.data);
            }).catch((err: any) => {
                reject(err);
            });
        });
    };

    return {
        viewNotesVisible,
        viewNotesObj,
        detailVisible,
        detailObj,
        detailRow,
        handleViewNotes,
        handleOpenDetail
    }
};

export default useViewNotes;